package com.ja.rfid.config;

import com.ja.rfid.vo.CardVo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Kisen
 * @email liuqs@jaid.cn
 * @date 2022/11/9 11:52
 * @detail
 */
@Configuration
public class RFIDConfig {

    //应答模式
    @Value("${ja.rfid.answer.write.ipaddr}")
    private String writeIpaddr;

    @Value("#{'${ja.rfid.answer.read.ipaddr}'.split(',')}")
    private String[] readIpaddr;

    @Value("${ja.rfid.answer.port}")
    private Integer port;

    @Value("${ja.rfid.answer.orgAddr}")
    private String orgAddr;

    @Value("${ja.rfid.answer.passWord}")
    private String passWord;

    @Bean
    public CardConfigBean cardConfigBean() {
        CardConfigBean bean = new CardConfigBean();
        CardVo writeCard = new CardVo();
        writeCard.setIpAddr(writeIpaddr);
        writeCard.setPort(port);
        writeCard.setOrgAddr(orgAddr);
        writeCard.setPassWord(passWord);
        bean.setWriteCard(writeCard);

        List<CardVo> readCardList = new ArrayList<>();
        for (int i = 0; i < readIpaddr.length; i++) {
            CardVo readCard = new CardVo();
            readCard.setIpAddr(readIpaddr[i]);
            readCard.setPort(port);
            readCard.setOrgAddr(orgAddr);
            readCard.setPassWord(passWord);
            readCardList.add(readCard);
        }
        bean.setReadCardList(readCardList);
        return bean;
    }
}
